<extend name="Base/common" />
<block name="body">
<div class="span9 page_message">
	<section id="contents">
      <include file="Addons/_nav" />
      
      <div class="tab-content has-weixinpreivew"> 
      
        <form action="{:U('config')}" class="form-horizontal fl" method="post">
            <empty name="custom_config">
                <foreach name="data['config']" item="form" key="o_key">
                    <div class="form-item cf">
                        <label class="item-label">
                            {$form.title|default=''}
                            <present name="form.tip">
                                <span class="check-tips">{$form.tip}</span>
                            </present>
                        </label>
                            <switch name="form.type">
                                <case value="text">
                                <div class="controls">
                                    <input id="cardName" type="text" name="config[{$o_key}]" class="text input-large" value="{$form.value}">
                                </div>
                                </case>
                                <case value="password">
                                <div class="controls">
                                    <input type="password" name="config[{$o_key}]" class="text input-large" value="{$form.value}">
                                </div>
                                </case>
                                <case value="hidden">
                                    <input type="hidden" name="config[{$o_key}]" id="hidden_{$o_key}" value="{$form.value}">
                                </case>
                                <case value="radio">
                                <div class="controls">
                                    <foreach name="form.options" item="opt" key="opt_k">
                                        <label class="radio">
                                            <input type="radio" name="config[{$o_key}]" value="{$opt_k}" <eq name="form.value" value="$opt_k"> checked</eq>>{$opt}
                                        </label>
                                    </foreach>
                                </div>
                                </case>
                                <case value="checkbox">
                                <div class="controls">
                                    <foreach name="form.options" item="opt" key="opt_k">
                                        <label class="checkbox">
                                            <php>
                                                is_null($form["value"]) && $form["value"] = array();
                                            </php>
                                            <input type="checkbox" name="config[{$o_key}][]" value="{$opt_k}" <in name="opt_k" value="$form.value"> checked</in>>{$opt}
                                        </label>
                                    </foreach>
                                </div>
                                </case>
                                <case value="select">
                                <div class="controls">
                                    <select name="config[{$o_key}]" id="select_{$o_key}">
                                        <foreach name="form.options" item="opt" key="opt_k">
                                            <option value="{$opt_k}" <eq name="form.value" value="$opt_k"> selected</eq>>{$opt}</option>
                                        </foreach>
                                    </select>
                                </div>
                                <if condition="$o_key=='background'">
                                 <!-- 自定义上传背景 -->
                                <div class="controls uploadrow" id="uploadControls" style="display:none">
                                    <input type="file" id="upload_picture_bg">
                                    <input type="hidden" name="config[bg]" id="cover_id_bg"/>
                                    <div class="upload-img-box" rel='img'>
                                      <notempty name="data[bg]">
                                        <div class="upload-pre-item"><img width="120" height="120" src="__ROOT__{$data[bg]|get_cover='path'}"/></div>
                                      </notempty>
                                    </div>
                                  </div>
                                  <script type="text/javascript">
                                        //上传图片
                                        /* 初始化上传插件 */
                                        $("#upload_picture_bg").uploadify({
                                            "height"          : 120,
                                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                            "fileObjName"     : "download",
                                            "buttonText"      : "上传卡片图片",
                                            "uploader"        : "{:U('home/File/uploadPicture',array('session_id'=>session_id()))}",
                                            "width"           : 120,
                                            'removeTimeout'	  : 1,
                                            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                                            "onUploadSuccess" : uploadPicturebg
                                        });
                                        function uploadPicturebg(file, data){
                                            var data = $.parseJSON(data);
                                            var src = '';
                                            if(data.status){
                                                $("#cover_id_bg").val(data.id);
                                                src = data.url || '__ROOT__' + data.path;
                                                $('#cardBg').attr("href",src);
                                                $('#cardBgImg').attr("src",src);
												 $("#cover_id_bg").parent().find('.upload-img-box').html(
                                                '<div class="upload-pre-item"><img width="120" height="120" src="' + src + '"/></div>'
                                            );
                                            } else {
                                                updateAlert(data.info);
                                                setTimeout(function(){
                                                    $('#top-alert').find('button').click();
                                                    $(that).removeClass('disabled').prop('disabled',false);
                                                },1500);
                                            }
                                        }
                                </script> 
                                </if>
                                </case>
                               
                                <case value="textarea">
                                <div class="controls">
                                    <label class="textarea input-large">
                                        <textarea name="config[{$o_key}]">{$form.value}</textarea>
                                    </label>
                                </div>
                                </case>
                                
                            </switch>
                        </div>
                </foreach>
            <else />
                <present name="custom_config">
                    {$custom_config}
                </present>
            </empty>
            <input type="hidden" name="id" value="{$data.id}" readonly>
            <button type="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定</button>
            
        </form>
        <div class="card_preview fr">
      		<a id="cardBg" href="{:ADDON_PUBLIC_PATH}/card_bg_1.png" target="_blank"><img id="cardBgImg" src="{:ADDON_PUBLIC_PATH}/card_bg_1.png" width="100%" height="100%"></a>
            <span class="card_num" id="cardNumber">NO. 80001</span>
            <span class="card_name"></span>
       </div>
      </div>
    </section>
 </div>
</block>

<block name="script">
<script type="text/javascript" charset="utf-8">
	//导航高亮
    $('.side-sub-menu').find('a[href="{:U('Addons/index')}"]').closest('li').addClass('current');
    if($('ul.tab-nav').length){
    	$('.btn-return').hide();
    }
	$(function(){
		showTab();
		$('#select_background').change(function(){
				if($(this).val()==11){
					$('#uploadControls').show();
				}else{
					var cardBgUrl = '{:ADDON_PUBLIC_PATH}/card_bg_'+$(this).val()+".png";
					$('#cardBg').attr("href",cardBgUrl);
					$('#cardBgImg').attr("src",cardBgUrl);
					$('#uploadControls').hide();
				}
		});
		$('#select_length').change(function(){
			var val = 'NO. '+$(this).val();
			$('#cardNumber').html(val);
		});		
		$('#cardName').keyup(function(){
			$('.card_name').html($(this).val());
		})
		
		//初始化
		$('.card_name').html($('#cardName').val());
		$('#cardNumber').html('NO. '+$('#select_length').val());
		if($('#select_background').val()==11){
			$('#uploadControls').show();
			var cardBgUrl = $("#hidden_background_custom").val();
		}else{
			var cardBgUrl = '{:ADDON_PUBLIC_PATH}/card_bg_'+$('#select_background').val()+".png";

		}	
		$('#cardBg').attr("href",cardBgUrl);
		$('#cardBgImg').attr("src",cardBgUrl);	
	})
</script>
</block>
